#include<bits/stdc++.h>

using namespace std;

int months[] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

bool check(int data) {
	int year = data / 10000;
	int month = data % 10000 / 100;
	int day = data % 100;

	if (!day || month <= 0 || month > 12)return false;
	if (month != 2 && day > months[month])return false;
	if (month == 2) {
		if ((year % 100 != 0 && year % 4 == 0) || year % 400 == 0) {
			if (day > 29)return false;
		} else {
			if (day > 28)return false;
		}
	}
	return true;
}

bool check1(string s) {
	int len = s.size();
	for (int i = 0, j = len - 1; i < j ; i++, j--) {
		if (s[i] != s[j])return false;
	}
	return true;
}

bool check2(string s) {
	if (check1(s)) {
		if (s[0] != s[2] || s[1] != s[3] || s[0] == s[1])return false;
		return true;
	}
	return false;
}

int main() {
	int data;
	cin >> data;
	int flag = 0;
	int flag1 =0; 
	for (int i = data + 1 ; i < 89991231; i++) {
		if(flag1 == 2)break;
		if (check(i)) {
			string s = to_string(i);
			if (!flag && check1(s)) {
				flag = 1;
				cout << i << endl;
				flag1++;
			}
			if (check2(s)) {
				cout << i << endl;
				flag1++;
			}
		}
	}
	return 0;
}
